package com.wch.SpringBootTestDemo.jwt;

import java.util.Date;

import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

/**
 * 测试Jwt,自定义claims
 * @author 19821
 *
 */
public class CreateJwtTest3 {

	public static void main(String[] args) {
		long now = System.currentTimeMillis();  //获取当前时间
		long exp = now + 1000*60; //过期时间为1分钟
		JwtBuilder builder = Jwts.builder().setId("888")
					  .setSubject("小白")
					  .setIssuedAt(new Date())  //签发时间
					  .setExpiration(new Date(exp))  //过期时间
					  .signWith(SignatureAlgorithm.HS256,"itcast")  //签发密钥
					  .claim("roles", "admin")   //自定义claims
					  .claim("us", "fzl")
					  .claim("logo", "logo.png"); //自定义claims
		System.out.println(builder.compact());
		
	}
}
